package com.aaa.hospital.ManagementEnd.controller;


import com.aaa.hospital.ManagementEnd.pojo.Appointment;
import com.aaa.hospital.ManagementEnd.pojo.Docuser;
import com.aaa.hospital.ManagementEnd.service.AppointmentService;
import com.aaa.hospital.ManagementEnd.service.Impl.DocuserServiceImpl;
import com.aaa.hospital.ManagementEnd.service.RegistrationServices;
import com.aaa.hospital.ManagementEnd.util.AppointmentDB;
import com.alibaba.druid.util.StringUtils;
import com.alibaba.fastjson.JSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;

@Controller
@RequestMapping("/appoint")
public class AppointmentController {


    //预约
    @Autowired
    private RegistrationServices registrationServices;
    @Autowired
    private AppointmentService appointmentService;

    @Autowired
    private DocuserServiceImpl docuserServiceImpl;

@RequestMapping("/tjcx")
@ResponseBody
    public String appointment(@RequestParam("yydid") Integer yydid,@RequestParam("visid") Integer visid) {
    Integer integer = registrationServices.regById(yydid);
    if (integer == 0) {
        return "0";
    } else {
        AppointmentDB appointmentDB = appointmentService.byVisId(visid);
        if (appointmentDB == null) {
            return "1";
        } else {
            return JSON.toJSONString(appointmentDB);
        }
    }
}

//查询在体检科室的医生
@RequestMapping("/seAll")
@ResponseBody
public List<Docuser> select() {

    return docuserServiceImpl.selectAll();
}

@RequestMapping("/appinsert")
@ResponseBody
public Boolean insert(Integer yydid, Integer  ksid, Integer visid, Integer did, Integer state, String notes){
    Appointment appointment=new Appointment();
    appointment.setVisid(visid);
    appointment.setKsid(ksid);
    appointment.setDid(did);
    appointment.setState(state);
    appointment.setNotes(notes);
   boolean upstate = registrationServices.upstate(yydid);
    if (upstate == true) {
        boolean insert = appointmentService.insert(appointment);
        if (insert == true) {
            return true;
        }else {
            return false;
        }
    }else {
        return false;
    }
}









    }









